package com.sugar.follow.up.module.business.controller.admin.followuptemplatequestion;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.sugar.follow.up.framework.common.pojo.PageParam;
import com.sugar.follow.up.framework.common.pojo.PageResult;
import com.sugar.follow.up.framework.common.pojo.CommonResult;
import com.sugar.follow.up.framework.common.util.object.BeanUtils;
import static com.sugar.follow.up.framework.common.pojo.CommonResult.success;

import com.sugar.follow.up.framework.excel.core.util.ExcelUtils;

import com.sugar.follow.up.framework.apilog.core.annotation.ApiAccessLog;
import static com.sugar.follow.up.framework.apilog.core.enums.OperateTypeEnum.*;

import com.sugar.follow.up.module.business.controller.admin.followuptemplatequestion.vo.*;
import com.sugar.follow.up.module.business.dal.dataobject.followuptemplatequestion.FollowUpTemplateQuestionDO;
import com.sugar.follow.up.module.business.service.followuptemplatequestion.FollowUpTemplateQuestionService;

@Tag(name = "管理后台 - 随访模板题目")
@RestController
@RequestMapping("/business/follow-up-template-question")
@Validated
public class FollowUpTemplateQuestionController {

    @Resource
    private FollowUpTemplateQuestionService followUpTemplateQuestionService;

    @PostMapping("/create")
    @Operation(summary = "创建随访模板题目")
    @PreAuthorize("@ss.hasPermission('business:follow-up-template:create')")
    public CommonResult<Long> createFollowUpTemplateQuestion(@Valid @RequestBody FollowUpTemplateQuestionSaveReqVO createReqVO) {
        return success(followUpTemplateQuestionService.createFollowUpTemplateQuestion(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新随访模板题目")
    @PreAuthorize("@ss.hasPermission('business:follow-up-template:update')")
    public CommonResult<Boolean> updateFollowUpTemplateQuestion(@Valid @RequestBody FollowUpTemplateQuestionSaveReqVO updateReqVO) {
        followUpTemplateQuestionService.updateFollowUpTemplateQuestion(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除随访模板题目")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('business:follow-up-template:delete')")
    public CommonResult<Boolean> deleteFollowUpTemplateQuestion(@RequestParam("id") Long id) {
        followUpTemplateQuestionService.deleteFollowUpTemplateQuestion(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除随访模板题目")
                @PreAuthorize("@ss.hasPermission('business:follow-up-template:delete')")
    public CommonResult<Boolean> deleteFollowUpTemplateQuestionList(@RequestParam("ids") List<Long> ids) {
        followUpTemplateQuestionService.deleteFollowUpTemplateQuestionListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得随访模板题目")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('business:follow-up-template:query')")
    public CommonResult<FollowUpTemplateQuestionRespVO> getFollowUpTemplateQuestion(@RequestParam("id") Long id) {
        FollowUpTemplateQuestionDO followUpTemplateQuestion = followUpTemplateQuestionService.getFollowUpTemplateQuestion(id);
        return success(BeanUtils.toBean(followUpTemplateQuestion, FollowUpTemplateQuestionRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得随访模板题目分页")
    @PreAuthorize("@ss.hasPermission('business:follow-up-template:query')")
    public CommonResult<PageResult<FollowUpTemplateQuestionRespVO>> getFollowUpTemplateQuestionPage(@Valid FollowUpTemplateQuestionPageReqVO pageReqVO) {
        PageResult<FollowUpTemplateQuestionDO> pageResult = followUpTemplateQuestionService.getFollowUpTemplateQuestionPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, FollowUpTemplateQuestionRespVO.class));
    }
}